<template>
  <div class="toast" v-show="isShow">
    <span>{{message}}</span>
  </div>
</template>

<script>
export default {
  data() {
    return {
      message: '',
      isShow: false,
    }
  },
  methods: {
    show(message, duration = 2000) {
      this.message = message
      this.isShow = true
      setTimeout(() => {
        this.isShow = false
        this.message = ''
      }, duration)
    },
  },
}
</script>

<style scoped>
.toast {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 99;
  padding: 8px 10px;
  border-radius: 5%;
  background-color: rgba(0, 0, 0, 0.65);
  color: #fff;

  animation: show 2s;
}
.toast span {
  animation: messageShow 2s;
}

@keyframes show {
  0% {
    visibility: hidden;
    background: rgba(0, 0, 0, 0);
  }
  50% {
    visibility: visible;
    background: rgba(0, 0, 0, 0.7);
  }
  100% {
    visibility: hidden;
    background: rgba(255, 255, 255, 0);
  }
}

@keyframes messageShow {
  0% {
    visibility: hidden;
    color: rgba(255, 255, 255, 0);
  }
  50% {
    visibility: visible;
    color: rgba(255, 255, 255, 1);
  }
  100% {
    visibility: hidden;
    color: rgba(255, 255, 255, 0);
  }
}
</style>